home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / cleandialog.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  9KB  |  290 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import operator
  5. from base.g import *
  6. from base import device, utils, maint
  7. from prnt import cups
  8. from base.codes import *
  9. from ui_utils import *
  10. from PyQt4.QtCore import *
  11. from PyQt4.QtGui import *
  12. from cleandialog_base import Ui_Dialog
  13. CLEAN_TYPE_INITIAL = 1000
  14. CLEAN_TYPE_TEST = 1001
  15. PAGE_START = 0
  16. PAGE_LEVEL_1 = 1
  17. PAGE_LEVEL_2 = 2
  18. PAGE_LEVEL_3 = 3
  19. PAGE_FRONT_PANEL = 4
  20. BUTTON_CLEAN = 0
  21. BUTTON_NEXT = 1
  22. BUTTON_FINISH = 2
  23.  
  24. def true():
  25.     return True
  26.  
  27.  
  28. class CleanDialog(QDialog, Ui_Dialog):
  29.     
  30.     def __init__(self, parent, device_uri):
  31.         QDialog.__init__(self, parent)
  32.         self.setupUi(self)
  33.         self.device_uri = device_uri
  34.         self.clean_type = CLEAN_TYPE_INITIAL
  35.         self.abort = False
  36.         self.seq_index = 0
  37.         self.step = 1
  38.         self.step_max = 0
  39.         self.max_steps = {
  40.             CLEAN_TYPE_UNSUPPORTED: 1,
  41.             CLEAN_TYPE_PCL: 4,
  42.             CLEAN_TYPE_LIDIL: 4,
  43.             CLEAN_TYPE_PCL_WITH_PRINTOUT: 4 }
  44.         self.seq = {
  45.             CLEAN_TYPE_INITIAL: [
  46.                 (self.showStartPage, None),
  47.                 (self.endStartPage, None)],
  48.             CLEAN_TYPE_UNSUPPORTED: [
  49.                 (self.showFrontPanelPage, None),
  50.                 (self.endFrontPanelPage, None),
  51.                 (self.close, None)],
  52.             CLEAN_TYPE_PCL: [
  53.                 (self.showLevel1Page, None),
  54.                 (self.endLevel1Page, None),
  55.                 (self.doClean, (1,)),
  56.                 (self.showLevel2Page, None),
  57.                 (self.endLevel2Page, None),
  58.                 (self.doClean, (2,)),
  59.                 (self.showLevel3Page, None),
  60.                 (self.endLevel3Page, None),
  61.                 (self.doClean, (3,)),
  62.                 (self.close, None)],
  63.             CLEAN_TYPE_LIDIL: [
  64.                 (self.showLevel1Page, None),
  65.                 (self.endLevel1Page, None),
  66.                 (self.doClean, (1,)),
  67.                 (self.showLevel2Page, None),
  68.                 (self.endLevel2Page, None),
  69.                 (self.doClean, (2,)),
  70.                 (self.showLevel3Page, None),
  71.                 (self.endLevel3Page, None),
  72.                 (self.doClean, (3,)),
  73.                 (self.close, None)],
  74.             CLEAN_TYPE_PCL_WITH_PRINTOUT: [
  75.                 (self.showLevel1Page, None),
  76.                 (self.endLevel1Page, None),
  77.                 (self.doClean, (1,)),
  78.                 (self.showLevel2Page, None),
  79.                 (self.endLevel2Page, None),
  80.                 (self.doClean, (2,)),
  81.                 (self.showLevel3Page, None),
  82.                 (self.endLevel3Page, None),
  83.                 (self.doClean, (3,)),
  84.                 (self.close, None)] }
  85.         self.initUi()
  86.         QTimer.singleShot(0, self.nextSequence)
  87.  
  88.     
  89.     def initUi(self):
  90.         self.connect(self.CancelButton, SIGNAL('clicked()'), self.CancelButton_clicked)
  91.         self.connect(self.NextButton, SIGNAL('clicked()'), self.NextButton_clicked)
  92.         self.connect(self.DeviceComboBox, SIGNAL('DeviceUriComboBox_noDevices'), self.DeviceUriComboBox_noDevices)
  93.         self.connect(self.DeviceComboBox, SIGNAL('DeviceUriComboBox_currentChanged'), self.DeviceUriComboBox_currentChanged)
  94.         self.DeviceComboBox.setFilter({
  95.             'clean-type': (operator.gt, 0) })
  96.         if self.device_uri:
  97.             self.DeviceComboBox.setInitialDevice(self.device_uri)
  98.         
  99.         self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
  100.  
  101.     
  102.     def NextButton_clicked(self):
  103.         self.nextSequence()
  104.  
  105.     
  106.     def nextSequence(self):
  107.         while True:
  108.             
  109.             try:
  110.                 (seq, params) = self.seq[self.clean_type][self.seq_index]
  111.             except IndexError:
  112.                 break
  113.  
  114.             if seq is None:
  115.                 self.seq_index += 1
  116.                 continue
  117.             
  118.             self.new_page = False
  119.             t = []
  120.             if params is not None:
  121.                 for p in params:
  122.                     
  123.                     try:
  124.                         t.append(p())
  125.                     continue
  126.                     t.append(p)
  127.                     continue
  128.  
  129.                 
  130.             
  131.             
  132.             try:
  133.                 seq.func_name(','.join % ([], []([ repr(x) for x in t ])))
  134.             except AttributeError:
  135.                 pass
  136.  
  137.             
  138.             try:
  139.                 seq(*t)
  140.             except Error:
  141.                 CheckDeviceUI(self)
  142.                 break
  143.  
  144.             self.seq_index += 1
  145.             if self.new_page:
  146.                 break
  147.             
  148.             if self.abort:
  149.                 self.close()
  150.                 continue
  151.  
  152.     
  153.     def showStartPage(self):
  154.         self.setCleanButton(BUTTON_NEXT)
  155.         num_devices = self.DeviceComboBox.setDevices()
  156.         if num_devices == 1:
  157.             self.skipPage()
  158.             return None
  159.         self.DeviceComboBox.updateUi()
  160.         self.displayPage(PAGE_START)
  161.  
  162.     
  163.     def endStartPage(self):
  164.         self.mq = device.queryModelByURI(self.device_uri)
  165.         self.clean_type = self.mq.get('clean-type', CLEAN_TYPE_NONE)
  166.         self.seq_index = -1
  167.         log.debug('clean-type=%d' % self.clean_type)
  168.         self.step_max = self.max_steps[self.clean_type]
  169.         
  170.         try:
  171.             self.dev = device.Device(self.device_uri)
  172.         except Error:
  173.             CheckDeviceUI(self)
  174.             return None
  175.  
  176.  
  177.     
  178.     def showLevel1Page(self):
  179.         self.setCleanButton(BUTTON_CLEAN)
  180.         self.displayPage(PAGE_LEVEL_1)
  181.  
  182.     
  183.     def endLevel1Page(self):
  184.         pass
  185.  
  186.     
  187.     def showLevel2Page(self):
  188.         self.displayPage(PAGE_LEVEL_2)
  189.  
  190.     
  191.     def endLevel2Page(self):
  192.         pass
  193.  
  194.     
  195.     def showLevel3Page(self):
  196.         self.displayPage(PAGE_LEVEL_3)
  197.  
  198.     
  199.     def endLevel3Page(self):
  200.         pass
  201.  
  202.     
  203.     def showFrontPanelPage(self):
  204.         self.setCleanButton(BUTTON_FINISH)
  205.         self.displayPage(PAGE_FRONT_PANEL)
  206.  
  207.     
  208.     def endFrontPanelPage(self):
  209.         pass
  210.  
  211.     
  212.     def DeviceUriComboBox_currentChanged(self, device_uri):
  213.         self.device_uri = device_uri
  214.  
  215.     
  216.     def DeviceUriComboBox_noDevices(self):
  217.         FailureUI(self, self._CleanDialog__tr('<b>No devices that support print cartridge cleaning found.</b><p>Click <i>OK</i> to exit.</p>'))
  218.         self.close()
  219.  
  220.     
  221.     def CancelButton_clicked(self):
  222.         self.close()
  223.  
  224.     
  225.     def doClean(self, level):
  226.         
  227.         try:
  228.             self.dev.open()
  229.         except Error:
  230.             CheckDeviceUI(self)
  231.         elif self.dev.isIdleAndNoError():
  232.             if self.clean_type in (CLEAN_TYPE_PCL, CLEAN_TYPE_PCL_WITH_PRINTOUT):
  233.                 if level == 1:
  234.                     maint.cleanType1(self.dev)
  235.                 elif level == 2:
  236.                     maint.primeType1(self.dev)
  237.                 else:
  238.                     maint.wipeAndSpitType1(self.dev)
  239.             elif self.clean_type == CLEAN_TYPE_LIDIL:
  240.                 if level == 1:
  241.                     maint.cleanType2(self.dev)
  242.                 elif level == 2:
  243.                     maint.primeType2(self.dev)
  244.                 else:
  245.                     maint.wipeAndSpitType2(self.dev)
  246.             
  247.             maint.print_clean_test_page(self.dev)
  248.         else:
  249.             CheckDeviceUI(self)
  250.         finally:
  251.             if self.dev is not None:
  252.                 self.dev.close()
  253.             
  254.  
  255.  
  256.     
  257.     def displayPage(self, page):
  258.         self.updateStepText(self.step)
  259.         self.step += 1
  260.         self.new_page = True
  261.         self.StackedWidget.setCurrentIndex(page)
  262.  
  263.     
  264.     def skipPage(self):
  265.         self.step += 1
  266.         self.new_page = False
  267.  
  268.     
  269.     def updateStepText(self, p = None):
  270.         if p is None or not (self.step_max):
  271.             self.StepText.setText(QString(''))
  272.         else:
  273.             self.StepText.setText(self._CleanDialog__tr('Step %1 of %2').arg(p).arg(self.step_max))
  274.  
  275.     
  276.     def setCleanButton(self, typ = BUTTON_CLEAN):
  277.         if typ == BUTTON_CLEAN:
  278.             self.NextButton.setText(self._CleanDialog__tr('Clean'))
  279.         elif typ == BUTTON_NEXT:
  280.             self.NextButton.setText(self._CleanDialog__tr('Next >'))
  281.         elif typ == BUTTON_FINISH:
  282.             self.NextButton.setText(self._CleanDialog__tr('Finish'))
  283.         
  284.  
  285.     
  286.     def __tr(self, s, c = None):
  287.         return qApp.translate('CleanDialog', s, c)
  288.  
  289.  
  290.